package cn.lili.modules.order.order.callback;

import cn.lili.common.vo.ResponseBean;
import cn.lili.common.vo.ResultMessage;
import cn.lili.exchange.AmqpExchangeProperties;
import cn.lili.modules.goods.entity.vos.yunxin.CallBackVO;
import cn.lili.modules.order.aftersale.service.AfterSaleService;
import cn.lili.modules.order.order.entity.dos.Order;
import cn.lili.modules.order.order.entity.dos.OrderItem;
import cn.lili.modules.order.order.service.OrderItemService;
import cn.lili.modules.order.order.service.OrderService;
import cn.lili.util.AmqpSender;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import java.util.HashMap;

/**
 * 订单取消
 */
@Service("order.cancel")
public class OrderCancelService implements MessageType{

    @Autowired
    private OrderItemService orderItemService;

    @Autowired
    @Lazy
    private OrderService orderService;

    @Override
    public ResponseBean execute(CallBackVO callBackVO) {
        //模糊搜索第三方平台id
        OrderItem orderItem = orderItemService.getOne(new LambdaQueryWrapper<OrderItem>().like(OrderItem::getOrderJsonVal, callBackVO.getOrder_sn()).last("limit 1"));
        Order orderServiceBySn = orderService.getBySn(orderItem.getOrderSn());

        //退款并把supplyChainState 修改成2（已售后）
        Order order = orderService.cancel(orderItem.getOrderSn(), "订单取消", orderServiceBySn.getBuyerId());
        order.setSupplyChainState(2);
        orderService.updateById(order);

        return new ResponseBean(0, "操作成功", new HashMap<>());
    }
}
